home *** CD-ROM | disk | FTP | other *** search
- /* filename: SendMail.rx */
- /* version: 1.3 15 Dec 94 (c)1994 James E. Dutton */
- /* purpose: take input file in Internet RFC822 (e-mail) format and convert */
- /* it into .txt and .wrk files for delivery via an SMTP client */
- /* syntax: (rx) SendMail <[input file specs] */
- /* notes: while this program can be invoked manually, it is intended to */
- /* be called by AmigaELM as a replacement for other SendMail */
- /* programs */
- /* author: Jim Dutton */
- /* jimd@slip106.termserv.siu.edu */
- /* ca0008@siucvmb.siu.edu */
- /* comments: Inspired by Sendmail.rx version 19931205 by Dan Rowan */
- /* */
- /* To invoke from AmigaELM, add/modify the "Sendmail"/"Rmail" */
- /* configuration parameters similar to (using your own directory) */
- /* */
- /* SendMail rexxc:rx tcpip:sendmail.rx <$MSG */
- /* RMail rexxc:rx tcpip:sendmail.rx <$MSG $TO */
- /* */
- /* Some SMTP clients (eg; AmigaNOS) are not able to deal with MX */
- /* records (or target hosts which do not sport an SMTP server and */
- /* require a seperate mail host to receive mail); an ARexx clip */
- /* list, needMXlist, is used to find which known hosts use an MX */
- /* record; another ARexx clip list is used to provide a known mail*/
- /* host which corresponds to the MX record for the original target*/
- /* host, and is called "useMXlist"; both of these lists are built */
- /* and maintained manually by the user via the ARexx RXSET command*/
- /* */
- /* For example: */
- /* RXSET needMXlist gwalter.demon.co.uk ppp11.llc.org aston.ac.uk */
- /* RXSET useMXlist post.demon.co.uk biko.llc.org email.aston.ac.uk*/
- /* */
- /* There is a simple one-to-one correspondance between a known */
- /* host in the needMXlist and the useMXlist. You will need access */
- /* to something like the NSLOOKUP program to find out the MX */
- /* record(s) associated with a given host, or you will need to */
- /* find a Domain Name Server related person who can find out that */
- /* information for you. */
- /* */
- /* You will need to change the value of the DefaultMailer variable*/
- /* to the host name of a "smart(er)" mail (SMTP) server which can */
- /* resolve host names that your SMTP client cannot; this should be*/
- /* an SMTP server (gateway) within your existing domain/network */
- /* */
- /* This SendMail program will process carbon copies and blind */
- /* carbon copies, but the keywords MUST be spelled correctly (see */
- /* Select clause below), and begin on seperate lines */
- /* */
- /* This program also allows MULTIPLE To:, Cc:, or Bcc: targets IF */
- /* each target is immediately followed by a comma (except for the */
- /* LAST target, of course) (eg; <target1>, <target2>) */
- /* */
- /* To:, Cc:, and Bcc: target lists may cover more than one line IF*/
- /* each line (but the last one) is terminated with a comma */
- /* */
- /* A log file is maintained for every note that is processed. A */
- /* few real sample log entries are: */
- /* */
- /* 20 Nov 1994 12:49:24 To: "Allen Wittenauer" <allenw@som.siu.edu> Subject: Re: Uproar? */
- /* 22 Nov 1994 19:54:23 To: majordomo@NetBSD.ORG Subject: lists */
- /* */
- /* You should modify the path for this log file to conform to your*/
- /* system (set in variable MailLogFile below) */
- /* */
- /* The path for the SMTP client's mail queue on your system should*/
- /* be verified against the MQueue variable below */
- /* */
- /* A working (temporary) copy of the note to be sent is kept on */
- /* the T: device */
- /* */
- /* This (pseudo) SendMail program is by NO means, exhaustive */
-
- Call Initialize
- Call ProcessInput
- Call CreateMqueue
- Call CloseUp
- Exit
-
-
- CloseUp:
- duh = open(seqfile,MQueue'/sequence.seq','W')
- duh = writech(seqfile,seq); duh = close(seqfile)
- duh = close(STDERR); duh = close(STDOUT); duh = close(maillog)
- Address 'COMMAND' 'Delete T:tempfile.txt'
- Return
-
-
- Initialize:
- DefaultMailer = "?"; MailLogFile = "TCPIP:Logs/Mail.log"
- MQueue = "TCPIP:spool/mqueue"
- EndOfHeaders = no; ReturnTrip = no; TargetNum = 0; tabchar = '09'x
-
- If ~open(seqfile,MQueue'/sequence.seq','R') then
- Do; say "***Can't open sequence.seq file, aborting!"; Exit 20; End
- seq = readln(seqfile); duh = close(seqfile)
-
- needMXlist = getclip("needMXlist") /* list of known hosts which require an MX host */
- useMXlist = getclip("useMXlist") /* use these MX hosts instead of host above */
- If needMXlist = "" then needMXlist = "?" /* dummy record */
- Else upper needMXlist
- If useMXlist = "" then useMXlist = "?" /* dummy record */
- Else upper useMXlist
-
- If open(timezone,'ENV:TZ','R') then; Do; tz=left(readln(timezone),3); duh = close(timezone); End
- Else tz = "GMT"
-
- If ~open(maillog,MailLogFile,"A") then duh = open(maillog,MailLogFile,"W")
- duh = open(STDERR,"T:SendmailErrors","W"); duh = open(STDOUT,"T:SendmailConsole","W")
- duh = open(tempfile,"T:tempfile.txt","W")
- duh = writeln(tempfile,'Date: '|| left(date('W'),3) ||', '|| date() ||' '|| time()||' '||tz)
- Return
-
-
- ProcessInput:
- Do while EndOfHeaders = no
- inline = strip(readln(STDIN))
- If substr(inline,1,5) ~= "Bcc: " then duh = writeln(tempfile,inline)
- Select
- When substr(inline,1,6) = "From: " then Call ProcessFromLine
- When substr(inline,1,4) = "To: " then Call ProcessToLines
- When substr(inline,1,4) = "Cc: " then Call ProcessToLines
- When substr(inline,1,9) = "Subject: " then subjline = inline
- When substr(inline,1,5) = "Bcc: " then Call ProcessToLines
- When ReturnTrip ~= no Then Interpret "Call" ReturnTrip
- Otherwise; If inline = "" then EndOfHeaders = yes
- End
- End
-
- Do while ~eof(STDIN); duh = writeln(tempfile,readln(STDIN)); End
- duh = close(STDIN); duh = close(tempfile)
- Return
-
-
- ProcessFromLine:
- If pos("<",inline) > 0 then parse var inline "<"sendinguser">"
- Else parse var inline . sendinguser .
- Return
-
-
- ProcessToLines:
- If pos(",",inline) > 0 then
- Do; ReturnTrip = "ProcessToLines"; parse var inline inline","; End
- Else ReturnTrip = no
-
- TargetNum = TargetNum + 1; ToLine.TargetNum = inline
- If pos("<",inline) > 0 then parse var inline "<"targetuser">"
- Else
- If pos("(",inline) > 0 then
- Do
- parse var inline before"(".")"after; before = strip(before)
- If before ~= "" then targetuser = before
- Else targetuser = after
-
- If pos(":",targetuser) > 0 then targetuser = subword(targetuser,2)
- Else
- If substr(targetuser,1,1) = tabchar then parse var targetuser . +1 targetuser
- End
- Else targetuser = subword(inline,2)
-
- /* determine initial host to route mail to */
- If pos("%",targetuser) > 0 then
- Do
- parse var targetuser userid"%"userhost"@"routinghost .
- targetuser = userid"@"userhost
- End
- Else parse var targetuser"@"routinghost .
-
- /* check for known hosts who require an (alternative) MX host */
- uppered_routinghost = routinghost; upper uppered_routinghost
- loc = find(needMXlist,uppered_routinghost)
- If loc > 0 then routinghost = word(useMXlist,loc)
-
- /* check for nasty UUCP addresses and convert */
- upper inline
- If pos("UUCP",inline) > 0 then
- Do
- routinghost = DefaultMailer; parse var targethost lhs"@"rhs".uucp" .
- targetuser = lhs"%"rhs"@uunet.uu.net"
- End
-
- TargetUser.TargetNum = targetuser; RoutingHost.TargetNum = routinghost
- Return
-
-
- CreateMqueue:
- Do i = 1 to TargetNum
- seq = seq + 1
- duh = writeln(maillog,date() time() ToLine.i subjline)
- duh = open(mailwrk,MQueue'/'seq'.wrk','W')
- duh = writeln(mailwrk,RoutingHost.i); duh = writeln(mailwrk,sendinguser)
- duh = writeln(mailwrk,TargetUser.i); duh = close(mailwrk)
- Address 'COMMAND' 'COPY T:tempfile.txt TO' MQueue'/'seq'.txt'
- End
- Return
-